ALTER PROCEDURE [dbo].[CPP_User_Day7Signin]
  @dwUserID INT,    -- 用户ID
  @szResult NVARCHAR(255) OUTPUT  -- 输出信息
AS
BEGIN

	SET NOCOUNT ON
  
  DECLARE @Channel INT = 0
  SELECT @Channel = Channel FROM RYAccountsDB.dbo.AccountsInfo WHERE AccountsType = 0 AND UserID = @dwUserID
  IF @@ROWCOUNT=0 BEGIN
    SET @szResult = N'玩家[' + CAST(@dwUserID AS NVARCHAR) + ']不存在'
    RETURN 1
  END

  DECLARE @TotalReward INT = 0
  SELECT @TotalReward = COUNT(ID) FROM [RYPlatformDB].[dbo].[SigninConfig] WHERE Channel = @Channel
  IF @TotalReward<>7 BEGIN
    SET @szResult = N'未配置渠道[' + CAST(@Channel AS NVARCHAR) + ']的七日签到奖励'
    RETURN 2
  END


	DECLARE @SignCount INT = 0	-- 连续签到天数
	DECLARE @SignToday INT = 0	-- 今天是否签到
	DECLARE @CurrDay DATETIME = GETDATE()
	DECLARE @SignDay DATETIME = @CurrDay

	-- 进行循环判断之前一天是否签到
	WHILE EXISTS(SELECT null FROM RYRecordDB.dbo.RecordSignin WHERE UserID = @dwUserID AND DATEDIFF(dd, CollectDate, @SignDay) = 1) BEGIN
		SET @SignCount = @SignCount + 1
		SET @SignDay = DATEADD(dd, -1, @SignDay)
	END

	IF EXISTS(SELECT null FROM RYRecordDB.dbo.RecordSignin WHERE UserID = @dwUserID AND DATEDIFF(dd, CollectDate, @CurrDay) = 0) BEGIN
		SET @SignToday = 1
	END

  (
    SELECT
      0 AS Tab, DayID AS aaa, RewardGold AS bbb,
			ROW_NUMBER () OVER (ORDER BY [DayID] ASC) AS ROW_NUMBER
    FROM [RYPlatformDB].[dbo].[SigninConfig] WHERE Channel = @Channel
  )
  UNION ALL
  (
		SELECT 1 AS Tab, 0 AS aaa, @SignToday AS bbb, 1 AS ROW_NUMBER
  )
  UNION ALL
  (
		SELECT 1 AS Tab, 0 AS aaa, @SignCount AS bbb, 2 AS ROW_NUMBER
	)
  SET @szResult = 'SUCCESS'
  RETURN 0
END